import pandas as pd
from pyecharts.charts  import Bar
from pyecharts import options as opts

data = pd.read_excel("问题反馈.xlsx")
feedback_counts = data.groupby(["createdAt","feedbackType"])['id'].count().fillna(0)

# 将 MultiIndex Series 转换为 DataFrame
feedback_df = feedback_counts.reset_index()
feedback_df.columns  = ['日期', '反馈类型', '数量']

# 获取唯一日期和反馈类型列表
dates = feedback_df['日期'].unique().tolist()
types = feedback_df['反馈类型'].unique().tolist()

from pyecharts.charts import Calendar
from pyecharts.globals import ThemeType

# 计算每日总反馈量
daily_totals = feedback_df.groupby('日期')['数量'].sum().reset_index()

pivot_table = feedback_counts.unstack(fill_value=0)
pivot_table.to_excel("pivot_table.xlsx")

calendar = Calendar(init_opts=opts.InitOpts(theme=ThemeType.CHALK))
calendar.add(
    "",
    [list(z) for z in zip(daily_totals['日期'].astype(str), daily_totals['数量'])],
    calendar_opts=opts.CalendarOpts(range_="2023")  # 修改为你的年份
)

calendar.set_global_opts(
    title_opts=opts.TitleOpts(title="每日反馈热力图"),
    visualmap_opts=opts.VisualMapOpts(max_=daily_totals['数量'].max())
)

calendar.render("feedback_calendar.html")


